package com.aierkeji.call.cms.dao.jpa;

import java.util.Date;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.aierkeji.call.cms.dao.BaseJPADao;
import com.aierkeji.call.cms.entity.AkjCallSystemHistory;

public interface AkjCallSystemHistoryDao extends BaseJPADao<AkjCallSystemHistory, Long> {
	String baseSql = "select t from AkjCallSystemHistory t  join AkjCallUser a on a.id = t.createdBy where (t.content like :content or :content is null )"
			+ " and (t.createdAt>=:startDate) "
			+ " and (t.createdAt<=:endDate) ";

	@Query(baseSql + " and (t.createdBy = :createdBy ) order by t.createdAt desc ")
	public Page<AkjCallSystemHistory> getList(Pageable pageable, @Param("createdBy") Long createdBy,
			@Param("content") String content, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	@Query(baseSql + " and (t.createdBy = :createdBy or a.leaderId = :leaderId ) order by t.createdAt desc ")
	public Page<AkjCallSystemHistory> getList(Pageable pageable, @Param("createdBy") Long createdBy,@Param("leaderId") Long leaderId,
			@Param("content") String content, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	@Query(baseSql + " order by t.createdAt desc ")
	public Page<AkjCallSystemHistory> getList(Pageable pageable, @Param("content") String content,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

}
